package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.Search;
import com.sc.nft.entity.SearchRelevance;
import com.sc.nft.mapper.SearchRelevanceMapper;
import com.sc.nft.sup.SuperEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 搜索配置关联(SearchRelevance)表Dao层
 *
 * @author 王伟成
 * @since 2024-03-07 17:21:04
 */
@Slf4j
@Repository
public class SearchRelevanceDao extends ServiceImpl<SearchRelevanceMapper, SearchRelevance> {

    /**
     * 通过藏品id获取关联属性的id
     *
     * @param id
     * @return
     */
    public Search getByCollectionId(Long id) {
        return baseMapper.getByCollectionId(id);
    }

    public SearchRelevance getRelevanceByCollectionId(Long collectionId)
    {
        return lambdaQuery().eq(SearchRelevance::getCollectionId,collectionId).eq(SuperEntity::getIsDelete,Boolean.FALSE).one();
    }

    /**
     * 根据藏品Id更新记录
     *
     * @param id
     */
    public void removeByCollectionId(Long id) {
        LambdaUpdateWrapper<SearchRelevance> objectLambdaUpdateWrapper = Wrappers.lambdaUpdate();
        objectLambdaUpdateWrapper.eq(SearchRelevance::getCollectionId, id);
        objectLambdaUpdateWrapper.set(SearchRelevance::getIsDelete, Boolean.TRUE);
        update(objectLambdaUpdateWrapper);
    }

    /**
     * 批量新增
     *
     * @param searchRelevanceList
     */
    public void insertBatch(List<SearchRelevance> searchRelevanceList) {
        baseMapper.insertBatch(searchRelevanceList);
    }
}
